long to binary c#

161

long to binary c# -

using System;
class Demo {
   static void Main() {
      long val = 753458;
      Console.WriteLine("Long: "+val);
      Console.Write("Binary String: "+Convert.ToString(val, 2));
   }
}

c# string to binary -

public static byte[] ConvertToByteArray(string str, Encoding encoding)
{
    return encoding.GetBytes(str);
}

public static String ToBinary(Byte[] data)
{
    return string.Join(" ", data.Select(byt => Convert.ToString(byt, 2).PadLeft(8, '0')));
}

// Use any sort of encoding you like. 
var binaryString = ToBinary(ConvertToByteArray("Welcome, World!", Encoding.ASCII));

Comments

Submit
0 Comments